home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d8 / pautolog.arc / PAUTOLOG.C < prev    next >
C/C++ Source or Header  |  1990-03-17  |  8KB  |  266 lines

  1. /*
  2. **  PRODIGY AutoLogon File Generator
  3. **
  4. **  Rich Taylor, 3/17/90
  5. */
  6.  
  7. /* includes */
  8. #include    <stdlib.h>
  9. #include    <stdio.h>
  10. #include    <string.h>
  11. #include    <ctype.h>
  12. #include    <conio.h>
  13.  
  14. /* defines */
  15. #define TRUE    1
  16. #define FALSE   0
  17.  
  18. /* prototypes */
  19. static void near pascal  write_keytrace_string( FILE *fp, char *str );
  20. static void near pascal  write_keytrace_char( FILE *fp, char byCh );
  21. static unsigned char near pascal check_prodigy_id( char * );
  22. static void near pascal  get_string( char *, int );
  23.  
  24. int main (int argc, char *argv[]);
  25.  
  26. /* -------------------------------------------------------------------------- */
  27. int main (int argc, char *argv[])
  28. {
  29. FILE    *fp;
  30. int     i;
  31. char    szFileName[_MAX_PATH];
  32. char    szId[100];
  33. char    szPass[100];
  34. unsigned char   bIdFound, bPassFound;
  35.  
  36.     /* print banner */
  37.     printf( "PRODIGY AutoLogon Generator, v1.00.00, 3/17/90\n" );
  38.     printf( "Copyright (C) 1990, Rich Taylor (ID = PFTM42A)\n" );
  39.     printf( "PRODIGY is a registered service mark and trademark of Prodigy Services Co.\n\n" );
  40.  
  41.     printf( "Use /? command line option for HELP.\n\n" );
  42.  
  43.     /* check for command line data */
  44.        /* /?   -  display help */
  45.        /* /o   -  alternate output filename */
  46.        /* /i   -  ID string */
  47.        /* /p   -  Password string */
  48.  
  49.     /* search for /? : print help */
  50.     for( i=1; i<=argc; i++ )
  51.         if( 0 == strcmp( "/?", argv[i]) )
  52.             {
  53.             printf( "This program will create a keystroke input file that performs an automatic\n" );
  54.             printf( "logon to the PRODIGY service.  The data is written to a file named\n" );
  55.             printf( "KEYTRACE.AUT (unless you override the filename).  If you do not specify\n" );
  56.             printf( "your ID and password on the command line, the program will prompt you.\n\n" );
  57.  
  58.             printf( "KEYTRACE.AUT must be in your PRODIGY directory to work.\n\n" );
  59.  
  60.             printf( "Note - PRODIGY ID's are checked for valid form: AAAADDM, where\n" );
  61.             printf( "       A = letter (A-Z), D = digit (0-9), and M = member letter (A-F)\n\n" );
  62.  
  63.             printf( "Command Line Arguments:\n" );
  64.             printf( "  /o <filename>       to change output filename\n" );
  65.             printf( "  /i <ID>             to indicate ID\n" );
  66.             printf( "  /p <Password chars> to indicate password\n\n" );
  67.             exit( 0 );
  68.             }
  69.     printf( "<CR> terminates program from input prompt.\n" );
  70.  
  71.     /* search for /o : new output filename */
  72.     strcpy( szFileName, "KEYTRACE.AUT" );
  73.     for( i=1; i<=argc; i++ )
  74.         if( 0 == strcmp( "/o", argv[i]) || 0 == strcmp( "/O", argv[i]) )
  75.             {
  76.             if( i+1 > argc )
  77.                 {
  78.                 printf( "Missing output filename\n" );
  79.                 exit( 10 );
  80.                 }
  81.             else
  82.                 strcpy( szFileName, argv[i+1] );
  83.             }
  84.  
  85.     /* search for /i : ID string */
  86.     bIdFound = FALSE;
  87.     for( i=1; i<=argc; i++ )
  88.         if( 0 == strcmp( "/i", argv[i]) || 0 == strcmp( "/I", argv[i]) )
  89.             {
  90.             if( i+1 > argc )
  91.                 {
  92.                 printf( "Missing ID.\n" );
  93.                 exit( 10 );
  94.                 }
  95.             else
  96.                 {
  97.                 bIdFound = TRUE;
  98.                 strcpy( szId, argv[i+1] );
  99.                 }
  100.             }
  101.  
  102.     /* search for /p : password string */
  103.     bPassFound = FALSE;
  104.     for( i=1; i<=argc; i++ )
  105.         if( 0 == strcmp( "/p", argv[i]) || 0 == strcmp( "/P", argv[i]) )
  106.             {
  107.             if( i+1 > argc )
  108.                 {
  109.                 printf( "Missing Password.\n" );
  110.                 exit( 10 );
  111.                 }
  112.             else
  113.                 {
  114.                 bPassFound = TRUE;
  115.                 strcpy( szPass, argv[i+1] );
  116.                 }
  117.             }
  118.  
  119.     printf( "\n" );     /* insert space */
  120.  
  121.     /* Handle ID */
  122.     if( !bIdFound )
  123.         {  /* prompt for ID */
  124.         while( !bIdFound )
  125.             {
  126.             printf( "Enter Prodigy ID: " );
  127.             get_string( szId, 100 );
  128.  
  129.             if( 0 == strlen( szId ) )   /* No entry -> exit */
  130.                 return( 0 );
  131.  
  132.             bIdFound = check_prodigy_id( szId );
  133.             if( !bIdFound )
  134.                 printf( "    <- Not valid PRODIGY ID\n" );
  135.             else
  136.                 printf( "\n" );
  137.             }   /* ID entry loop */
  138.         }
  139.     else
  140.         /* check ID for correct PRODIGY format & change ID to uppercase */
  141.         if( !check_prodigy_id( szId ) )
  142.             {
  143.             printf( "\"%s\" is an invalid PRODIGY ID - must follow AAAADDM format,\n", szId );
  144.             printf( "    where A = letter (A-Z), D = digit (0-9), and M = member letter (A-F).\n" );
  145.             exit( 10 );
  146.             }
  147.  
  148.     /* prompt for Password */
  149.     if( !bPassFound )
  150.         {
  151.         printf( "Enter password: " );
  152.         get_string( szPass, 100 );
  153.         printf( "\n" );
  154.  
  155.         if( 0 == strlen( szPass ) )  /* No entry -> exit */
  156.             return( 0 );
  157.         }
  158.  
  159.      /* Open output file */
  160.     if( NULL == (fp = fopen( szFileName, "wb" )) )
  161.         {
  162.         printf( "Error opening file: [%s]\n", szFileName );
  163.         exit( 10 );
  164.         }
  165.  
  166.     /* write file */
  167.     write_keytrace_string( fp, szId );
  168.     write_keytrace_char( fp, '\x0D' );
  169.     write_keytrace_string( fp, szPass );
  170.     write_keytrace_char( fp, '\x0D' );
  171.  
  172.     fclose( fp );
  173.  
  174.     printf( "\nID = \"%s\", Password = \"%s\" written to %s\n", szId, szPass, szFileName );
  175.  
  176.     return( 0 );
  177.  
  178. } /* main() */
  179.  
  180. /* -------------------------------------------------------------------------- */
  181. static void near pascal  write_keytrace_string( FILE *fp, char *str )
  182. {
  183.     while( *str )
  184.         write_keytrace_char( fp, *str++ );
  185.  
  186. } /* write_keytrace_string() */
  187.  
  188. /* -------------------------------------------------------------------------- */
  189. static void near pascal  write_keytrace_char( FILE *fp, char byCh )
  190. {
  191.  
  192.     fprintf( fp, "%c", byCh );  /* write char */
  193.     fprintf( fp, "%c", '\0' );  /* write zero/null */
  194.  
  195. } /* write_keytrace_char() */
  196.  
  197. /* -------------------------------------------------------------------------- */
  198. static void near pascal get_string( str, maxlen )
  199. char    *str;
  200. int     maxlen;
  201. {
  202. int     pos = 0;
  203. unsigned char    crh = FALSE;
  204.  
  205. #define CR  0x0D
  206. #define BS  0x08
  207.  
  208.     while( !crh  &&  pos < maxlen-1 )
  209.         {
  210.         str[pos] = (char)getch();
  211.         if( CR == str[pos] )
  212.             {
  213.             crh = TRUE;
  214.             continue;
  215.             }
  216.         else if( BS == str[pos] )
  217.             {
  218.             if( 0 == pos )
  219.                 continue;
  220.             putch( 0x08 );  /* Backup over existing char */
  221.             putch( ' ' );   /* Erase char */
  222.             putch( 0x08 );  /* Backup of space */
  223.             pos --;
  224.             continue;
  225.             }
  226.  
  227.         putch( str[pos] );  /* echo */
  228.         pos++;
  229.         } /* character input loop */
  230.  
  231.     str[pos] = '\0';
  232.  
  233. } /* get_string() */
  234.  
  235. /* -------------------------------------------------------------------------- */
  236. static unsigned char near pascal check_prodigy_id( szId )
  237. char    *szId;
  238. {
  239. int     i, nlen;
  240.  
  241.     /* check for correct length */
  242.     if( 7 != (nlen = strlen( szId )) )
  243.         return( FALSE );
  244.  
  245.     /* first, convert string to uppercase */
  246.     for( i=0; i<nlen; i++ )
  247.         szId[i] = toupper( szId[i] );
  248.  
  249.     /* check that first 4 chars are alpha */
  250.     for( i=0; i<4; i++ )
  251.         if( !isalpha( szId[i] ) )
  252.             return( FALSE );
  253.  
  254.     /* check that next 2 chars are alpha */
  255.     for( i=4; i<6; i++ )
  256.         if( !isdigit( szId[i] ) )
  257.             return( FALSE );
  258.  
  259.     /* check that last character is in 'A' - 'F' */
  260.     if( NULL == strpbrk( &(szId[6]), "ABCDEF" ) )
  261.         return( FALSE );
  262.  
  263.     return( TRUE );
  264.  
  265. } /* check_prodigy_id() */
  266.